#pragma once
#include "dxrTypes.h"

class CommandListMgr
{
public:

	CommandListMgr(ID3D12DevicePtr device, D3D12_COMMAND_LIST_TYPE type, const wchar_t* name);
	CommandListMgr(ID3D12DevicePtr device, D3D12_COMMAND_LIST_TYPE type, ID3D12PipelineStatePtr state, const wchar_t* name);
    ~CommandListMgr();
	ID3D12GraphicsCommandList4Ptr get();
	void reset();

private:
    struct Record
    {
        Record(ID3D12DevicePtr device, D3D12_COMMAND_LIST_TYPE type, ID3D12PipelineStatePtr state);
        ~Record();
        void reset(ID3D12PipelineStatePtr state);

        ID3D12CommandAllocatorPtr allocator;
        ID3D12GraphicsCommandList4Ptr list;
    };
    using RecordPtr = std::shared_ptr<Record>;

    ID3D12DevicePtr m_device;
    D3D12_COMMAND_LIST_TYPE m_type;
    ID3D12PipelineStatePtr m_state;
    std::vector<RecordPtr> m_available, m_in_use;
    std::wstring m_name;
};

using CommandListMgrPtr = std::shared_ptr<CommandListMgr>;